package com.pzhu.user.domain.vo.converter;

import com.fasterxml.jackson.core.type.TypeReference;
import com.mybatisflex.core.paginate.Page;
import com.pzhu.user.domain.entity.Menu;
import com.pzhu.user.domain.enums.MenuType;
import com.pzhu.user.domain.vo.MenuSearchVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import com.pzhu.base.common.utils.json.JSONUtils;

@Mapper(
        componentModel = MappingConstants.ComponentModel.SPRING,
        imports = {JSONUtils.class, TypeReference.class, MenuType.class})
public interface MenuSearchVOConverter {

    @Mapping(target = "optimizeCountQuery", ignore = true)
    Page<MenuSearchVO> converter(Page<Menu> menu);

    @Mapping(
            target = "menuTagList",
            expression = "java(JSONUtils.toObj(menu.getMenuTagList(),new TypeReference<>() {}))")
    @Mapping(target = "meta", ignore = true)
    @Mapping(target = "type", expression = "java(menu.getType().getType())")
    MenuSearchVO converter(Menu menu);
}
